const express = require("express")

/* 创建路由器对象 */
const router = express.Router()

/* 定义路由 */
router.get("/",(req,res)=>{
    res.end("Hello from indexRouter")
})

// GET /get?name=heige&pwd=123456
// searchParams queryString
router.get("/get",(req,res)=>{
    res.end(JSON.stringify({
        ...req.query
    }))
})

// POST http://localhost:8002/post
// router.post("/post", urlencodedParser, function (req, res) {
    router.post("/post", function (req, res) {
        // res.send(
        //     JSON.stringify({
        //         msg:"msg from /post",
        //         ...req.body
        //     })
        // );
    
        res.json({
            msg: "msg from /post",
            ...req.body,
        });
    });

module.exports = router